<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
	<title>资源管理</title>
	<%@ include file="/common/meta.jsp" %>
    <%@ include file="/common/import.jsp" %>
	<%@ include file="uct-import.jsp" %>
		<script>
		$(function(){
			$('#actList').treegrid({
				title:'资源列表',
				iconCls:'icon-ok',
				fitColumns: true,
				nowrap: false,
				rownumbers: true,
				animate:true,
				collapsible:false,
				url:'${ctx}/uct/act/act!data.action?id=${id}',
				idField:'actId',
				treeField:'actCname',				
				frozenColumns:[[
	                {title:'资源名称',field:'actCname',width:200,
		                formatter:function(value){
		                	return '<span style="color:red">'+value+'</span>';
		                }
	                }
				]],
				
				columns:[[
					{field:'actEname',title:'资源标识',width:200},
					{field:'actType',title:'类型',width:100, 
						formatter:function(value){
							if(value=='menu'){
								return "菜单";
							}else{
								return "action";
							}
		                }
					},
					{field:'fullEname',title:'英文全称',width:200},
					{field:'fullCname',title:'中文全称',width:300},
					{field:'actStatus',title:'状态',width:80,
						 formatter:function(value){
		                	if(value=='1'){
								return '启动';
							}else if(value=='0'){
								return '停用';
							}else{
								 return "";
							}
		                }
					}
					//{field:'createTime',title:'创建时间',width:50}				
				]],
				onBeforeLoad:function(row,param){
					if (row){
						//$(this).treegrid('options').url = 'act-list!data.action';
					} else {
						//$(this).treegrid('options').url = 'act-list!data.action';
					}
				},
				toolbar:[		
		           {		        	  
		              	text:'增加子节点',
			              iconCls:'icon-add',
			              handler:function(){addSubAct();}
		        	  
		          },'-',		          
		          {
		              text:'修改',
		              iconCls:'icon-edit',
		              handler:function(){editAct();}
		          },'-',
		          {
		              text:'删除',
		              iconCls:'icon-cut',
		              handler:function(){deleteAct();}	             
		          },'-',
		          
		           {
		              text:'刷新节点',
		              iconCls:'icon-reload',
		              handler:function(){
		                  reload();
		             }
		          }/*,'-',
		          {
		              text:'持有用户列表',
		              iconCls:'icon-userinfo',	
		              handler:function(){
		                  actUserList();
		             }
		          }*/
		        ],
		        onBeforeLoad:function(row,param){
					if (row){
						$(this).treegrid('options').url = 'act!data.action';
					} 
				},
				onDblClickRow:function(row){
					editAct();
				}
			});
		});

				
		function addSubAct(){
			$('#saveActFrame').html('');
			var node = getSelected();
			var fatherId = "0";
			if(node){
				fatherId= node.actId;
				var url = '${ctx}/uct/act/add.action?fatherId='+fatherId;				
				$('#saveActFrame').attr("src",url);
				$('#saveActWin').window('open');	
			}
		}
		
		function editAct(){
			$('#saveActFrame').html('');
			var node = getSelected();			
			if(node){
				var url = '${ctx}/uct/act/add.action?id='+node.actId;
				$('#saveActFrame').attr("src",url);
				$('#saveActWin').window('open');			
			}				
		}
		
		function getSelected(){
			var selected = $('#actList').treegrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
		
		function reload(){
			var node = $('#actList').treegrid('getSelected');
			if (node){
				$('#actList').treegrid('reload', node.actId);
			} else {
				$('#actList').treegrid('reload');
			}
		}	
		
		function reloadTree(fatherId,nodeId){
			if(nodeId==""){
				var parent = $('#actList').treegrid('getParent',fatherId);
				if(parent){
					var parentId = parent["actId"]; 
					$('#actList').treegrid('reload', parentId);
				}else{
					$('#actList').treegrid('reload');
				}
			}else{
				$('#actList').treegrid('reload', fatherId);
			}
		}
			
		function reload_full(){
			$('#actList').treegrid('reload', '0');
		}
		
		function expandTo(){
			$('#actList').treegrid('expandTo', '0');
			$('#actList').treegrid('select', '0');
		}
			
		function deleteAct(){					
			var node = getSelected();	
			if(node){
		       $.messager.confirm('确认','您确定要删除:<font color="red">'+node.actCname+'</font> ？',function(r){
		          if(r){
						$.ajax({
								type: "post",
								url: "${ctx}/uct/act/del.action?id="+node.actId,
								success: function(data, textStatus){
									var result = jQuery.parseJSON(data);
									if(result.flag=='T'){
										$.messager.alert('结果', '操作成功', 'info');													
										$('#actList').treegrid('remove', node.actId);
									}else{
										$.messager.alert('结果', '操作失败：'+result.msg, 'error');													
									}		
								}
							});
		          }
		       });		             		
		    }	
		}
		
		function actUserList(){
		    var node = getSelected();
		    if(node){		    
				var url = '${ctx}/uct/act/act-user-list.action?actId='+node.actId;											
				$('#actUserListFrame').attr("src",url);
								
			    $('#actUserListWin').panel('open');
			    $('#actUserListWin').panel('setTitle','持有<font color=red>['+node.actCname+']</font> 资源的用户列表');
		    }		
		}
		
		function closeActAdd(){
			$('#saveActWin').window('close');
		}
		
	</script>
</head>

<body>
<table id="actList"></table>	

	
	<div id="saveActWin" class="easyui-window" title="资源管理" style="padding:5px;width: 400px;height:300;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   	 <iframe  frameborder="0"  id="saveActFrame" height="100%" width="100%" scrolling="No" frameborder="0" ></iframe>
    </div>
  
  	<div id="actUserListWin" class="easyui-window" title="持有用户" style="padding:5px;width: 650px;height:400;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   	 <iframe  frameborder="0"  id="actUserListFrame" height="100%" width="100%" scrolling="auto" frameborder="0" ></iframe>
    </div>  
</body>
</html>